﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>派送员管理</title>
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function () {
            initTable();
        });

        //初始化表格  
        function initTable() {
            $('#load').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                nowrap: true,
                autoRowHeight: true,
                striped: true,
                url: '/Taker/GetTaker',
                sortName: 'TakerID',
                sortOrder: 'asc',
                border: true,
                remoteSort: false,
                idField: 'TakerID',
                pageSize: 10,
                singleSelect: true,
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'TakerID', title: '编号', width: 50, sortable: true, align: 'center' },
                    { field: 'TakerName', title: '姓名', width: 100, sortable: true, align: 'center' },
                    { field: 'TakerPhone', title: "电话", width: 150, align: 'center', align: 'center' },
                    {
                        field: 'TakerRole', title: "类型", width: 100, sortable: true, align: 'center', formatter: function (val) {
                            if (val == 1) {
                                return '调度员';
                            }
                            else if (val == 2) {
                                return '送餐员';
                            }
                            else {
                                return '未知'
                            }
                        }
                    },
                    { field: 'TakerOpenID', title: "微信标识", width: 250, sortable: true, align: 'center', },
                    { field: 'YZM', title: "验证码", width: 150, align: 'center', align: 'center' },
                    {
                        field: 'YZMTime', title: "验证码有效时间", width: 250, sortable: true, align: 'center', formatter: function (val)
                        {
                            if (val != undefined)
                            {
                                var date = val.substring(0, 4) + "-" + val.substring(4, 6) + "-" + val.substring(6, 8) + " " + val.substring(8, 10) + ":" + val.substring(10, 12) + ":" + val.substring(12, 14);
                                return date;
                            }
                        }
                    },
                    {
                        field: 'IsWork', title: "接单状态", width: 100, sortable: true, align: 'center', formatter: function (val)
                        {
                            if (val == 1)
                            {
                                return '接单';
                            }
                            else if (val == 0) {
                                return '不接';
                            }
                            else
                            {
                                return '未知'
                            }
                        }
                    },
                    {
                        field: 'TakerState', title: "有效状态", width: 100, sortable: true, align: 'center', formatter: function (val) {
                            if (val == 0) {
                                return '无效';
                            }
                            else if (val == 1) {
                                return '有效';
                            }
                        }
                    },
                ]],
                toolbar: '#tb'
            });
        }

        //新增派送员
        function AddTaker() {
            $('#AddTakerDialog').dialog('open').dialog('setTitle', '新增派送员信息');
            
        }

        //新增派送员保存
        function BindAddTakerClickEvent() {
            //验证所有的文本框是否通过用户的验证
            var valid = $('#add_form').form('validate');
            if (valid == false) {
                return false;
            }
            var postdata = {
                TakerName: $("#a_takername").textbox('getValue'),
                TakerPhone: $("#a_takerphone").textbox('getValue'),
                IsWork: $("#a_iswork").combobox('getValue'),
                TakerRole: $("#a_isOrg").combobox('getValue'),
            };
            //发送异步请求到后台保存用户数据
            $.post("/Taker/SetTaker?Tag=" + 1, postdata, function (data) {
                if (data == "1") {
                    $.messager.alert("友情提示", "新增成功");
                    $('#AddTakerDialog').dialog('close');
                    $("#load").datagrid("reload");
                }
                else {
                    $.messager.alert("友情提示", "添加失败，请您检查");
                }
            });
            //});
        }

        //修改派送员信息对话框
        function UpdateTaker() {
            var UpdateInfoID = $("#load").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#UpdateTakerDialog").dialog("open").dialog("setTitle", "修改派送员信息");
                //$("input").removeAttr("checked");
                BingUpdate();
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }

        //绑定修改
        var TakerID;
        var YZM;
        var YZMTime;
        var TakerOpenID;
        function BingUpdate() {
            //首先获取选中的派送员信息
            var checkdata = $("#load").datagrid("getSelections")[0];
            if (checkdata != null) {
                TakerID = checkdata.TakerID;
                YZM = checkdata.YZM;
                YZMTime = checkdata.YZMTime;
                TakerOpenID = checkdata.TakerOpenID;
                $("#e_takername").textbox('setValue', checkdata.TakerName);  //姓名
                $("#e_takerphone").textbox('setValue', checkdata.TakerPhone); //电话号码
                $("#e_iswork").combobox('setValue', checkdata.IsWork);
                $("#e_isOrg").combobox('setValue', checkdata.TakerRole);
                //$("#edit_form input[name='rad'][value="+checkdata.IsWork+"]").attr("checked", true); //接单状态
            }

        }

        //修改保存
        function BindEditTakerClickEvent() {
            var postdata = {
                TakerID: TakerID,
                YZM: YZM,
                YZMTime:YZMTime,
                TakerOpenID:TakerOpenID,
                TakerName: $("#e_takername").textbox('getValue'),
                TakerPhone: $("#e_takerphone").textbox('getValue'),
                IsWork: $("#e_iswork").combobox('getValue'),
                TakerRole: $("#e_isOrg").combobox('getValue'),
            };
            //使用异步实现修改派送员信息
            $.post("/Taker/SetTaker?Tag=" + 2, postdata, function (data) {
                if (data == "1") {
                    $("#UpdateTakerDialog").dialog('close');
                    $.messager.alert("提示", "修改成功");
                    $("#load").datagrid('reload');
                    
                }
                else {
                    $.messager.alert("友情提示", "修改失败，请检查");
                }
            });
        }

        //删除派送员对话框
        function DeleteTaker() {
            var checkdata = $("#load").datagrid("getSelections");//获取整行数据
            if (checkdata.length == 1) {
                var checkdata = $("#load").datagrid("getSelections")[0];//获取整行数据
                var postdata = {
                    TakerID: checkdata.TakerID,
                    YZM:checkdata.YZM,
                    YZMTime: checkdata.YZMTime,
                    TakerOpenID: checkdata.TakerOpenID,
            };
            //console.log(postdata);
            //发送异步请求删除数据
            $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + checkdata.TakerName + "</font>这个派送员吗？", function (Del) {
                if (Del) {
                    $.post("/Taker/SetTaker?Tag=" + 3, postdata, function (data) {
                        if (data == "1") {
                            $.messager.alert("友情提示", "删除成功");
                            $("#load").datagrid('reload');
                        }
                        else {
                            $.messager.alert("友情提示", "删除失败:" + data);
                        }
                    });
                }
            });
        }

        else {
                $.messager.alert("友情提示", "每次只能删除一行数据，你已经选择了<font color='red' size='6'>" + checkdata.length + "</font>行");
        }
        }


        //派送员详细信息对话框
        function DetailTaker() {
            var UpdateInfoID = $("#load").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#DetailTakerDialog").dialog("open").dialog("setTitle", "派送员详细信息");
                Bingdetail();
            }
            else {
                $.messager.alert("友情提示", "请选择一行数据");
            }
        }
        ///绑定详细信息
        function Bingdetail() {
            var checkdata = $("#load").datagrid("getSelections")[0];
            if (checkdata != null) {
                var str = checkdata.YZMTime;
                var str_date = str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(6, 8) + " " + str.substring(8, 10) + ":" + str.substring(10, 12) + ":" + str.substring(12, 14);
                $("#d_takername").textbox('setValue', checkdata.TakerName);  //微信openid
                $("#d_takerphone").textbox('setValue', checkdata.TakerPhone);  //姓名
                $("#d_takeropenid").textbox('setValue', checkdata.TakerOpenID);
                $("#d_iswork").combobox('setValue', checkdata.IsWork);  //状态
                $("#d_yzm").textbox('setValue', checkdata.YZM);  //验证码
                $("#d_yzmtime").textbox('setValue', str_date);  //验证码有效期
                $("#d_isOrg").combobox('setValue', checkdata.TakerRole);  //验证码有效期
            }
        }

        //清空文本框中的值
        function ClearText() {
            $("#a_takername").textbox('setValue', "");
            $("#a_takerphone").textbox('setValue', "");
            $("#a_iswork").val('setValue', 1);
        }

    </script>
</head>
<body style="padding: 0">
    <!-- datagrid表格 -->
    <div>
        <table id="load" border="0"></table>
    </div>
    <!-- 工具栏 -->
    <div id="tb" style="padding: 5px; height: auto">
        <div style="margin-bottom: 5px">
            <a href="#" id="btndetail" class="easyui-linkbutton" iconcls="icon-more" onclick="DetailTaker()">详细信息</a>
            <a href="#" class="easyui-linkbutton" iconcls="icon-add" onclick="AddTaker()">新增</a>
            <a href="#" id="btnedit" class="easyui-linkbutton" iconcls="icon-edit" onclick="UpdateTaker()">修改</a>
            <a href="#" id="btndell" class="easyui-linkbutton" iconcls="icon-cancel" onclick="DeleteTaker()">删除</a>
            <hr style="margin-top: 5px" />
        </div>
    </div>

    <!--新增S-->
    <div id="AddTakerDialog" class="easyui-dialog" style="width: 300px; padding: 10px 0" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="add_form" method="post" novalidate="novalidate">
            <table>
                <tr style="height: 20px">
                    <td class="fr">姓名：</td>
                    <td>
                        <input id="a_takername" class="easyui-textbox" style="width: 150px; height: 20px" data-options="required:true"></td>
                </tr>
                <tr style="height: 20px">
                    <td class="fr">电话：</td>
                    <td>
                        <input id="a_takerphone" class="easyui-textbox" style="width: 150px; height: 20px" data-options="required:true"></td>
                </tr>
                <tr>
                    <td class="fr">类型：</td>
                    <td>
                        <select class="easyui-combobox" id="a_isOrg" style="width:80px" >
                            <option value="1">调度员</option>
                            <option value="2">送餐员</option>
                            </select>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="fr">是否接单：</td>
                    <td>
                        <select class="easyui-combobox" id="a_iswork" style="width:80px" >
                            <option value="1">接单</option>
                            <option value="0">不接</option>
                            </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="height: 30px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
                        <a id="btnAdd" href="#" onclick="BindAddTakerClickEvent()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">保存</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <!--新增E-->

    <!--修改S-->
    <div id="UpdateTakerDialog" class="easyui-dialog" style="width: 300px; padding: 10px 0" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="edit_form" method="post" novalidate="novalidate">
            <table>
                <tr style="height: 20px">
                    <td class="fr">姓名：</td>
                    <td>
                        <input id="e_takername" class="easyui-textbox" style="width: 150px; height: 20px" data-options="required:true"></td>
                </tr>
                <tr style="height: 20px">
                    <td class="fr">电话：</td>
                    <td>
                        <input id="e_takerphone" class="easyui-textbox" style="width: 150px; height: 20px" data-options="required:true"></td>
                </tr>
                <tr>
                    <td class="fr">类型：</td>
                    <td>
                        <select class="easyui-combobox" id="e_isOrg" style="width:80px" >
                            <option value="1">调度员</option>
                            <option value="2">送餐员</option>
                            </select>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="fr">是否接单：</td>
                    <td>
                        <select class="easyui-combobox" id="e_iswork" style="width:80px" >
                            <option value="1">接单</option>
                            <option value="0">不接</option>
                            </select>
                        @*<input  type="radio" name="rad" id="e_rad_Y" value="1" />接单
                        <input type="radio" name="rad" id="e_rad_N" value="0" />不接  *@
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="height: 30px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
                        <a id="btnUpdate" href="#" onclick="BindEditTakerClickEvent()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">保存修改</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <!--修改E-->

    <!--明细S-->
    <div id="DetailTakerDialog" class="easyui-dialog" style="width: 300px; padding: 10px 0" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="detaile_form" method="post" novalidate="novalidate">
            <table>
                <tr style="height: 20px">
                    <td class="fr">姓名：</td>
                    <td>
                        <input id="d_takername" class="easyui-textbox" style="width: 150px; height: 20px" readonly="true"></td>
                </tr>
                <tr style="height: 20px">
                    <td class="fr">电话：</td>
                    <td>
                        <input id="d_takerphone" class="easyui-textbox" style="width: 150px; height: 20px" readonly="true"></td>
                </tr>
                <tr style="height: 20px">
                    <td class="fr">微信标识：</td>
                    <td>
                        <input id="d_takeropenid" class="easyui-textbox" style="width: 150px; height: 20px" readonly="true"></td>
                </tr>
                
                <tr style="height: 20px">
                    <td class="fr">验证码：</td>
                    <td>
                        <input id="d_yzm" class="easyui-textbox" style="width: 150px; height: 20px" readonly="true"></td>
                </tr>
                <tr style="height: 20px">
                    <td class="fr">验证码有效时间：</td>
                    <td>
                        <input id="d_yzmtime" class="easyui-textbox" style="width: 150px; height: 20px" readonly="true"></td>
                </tr>
                <tr>
                    <td class="fr">类型：</td>
                    <td>
                        <select class="easyui-combobox" id="d_isOrg" style="width:80px" readonly="true">
                            <option value="1">调度员</option>
                            <option value="2">送餐员</option>
                            </select>
                    </td>
                </tr>
                <tr style="height: 20px">
                    <td class="fr">是否接单：</td>
                    <td>
                        <select id="d_iswork" name="d_Stat" class="easyui-combobox" style="width: 80px" readonly="true" >
                            <option value="1">接单</option>
                            <option value="0">不接</option >
                        </select>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <!--明细E-->

</body>
</html>
